import * as subjectApi  from '@/api/hmmm/subjects'
import * as simpleApi from '@/api/hmmm/tags'
import * as directoryApi from '@/api/hmmm/directorys'
import { list } from '@/api/hmmm/subjects'
const state = {
    subjectList: {},
    simpleList: {},
    tagList: {},
    subjectManagementList: {}
}
const mutations = {
    SET_SUBJECT_LIST: (state, newValue) => {
      console.log(newValue)
        state.subjectList = newValue
    },
    SET_SIMPLE_LIST: (state, newValue) => {
        state.simpleList = newValue
    },
    SET_TAG_LIST: (state, newValue) => {
        state.tagList = newValue
    },
    SET_SUBJECTMANAGEMENT_LIST: (state, newValue) => {
      newValue.data.items = newValue.data.items.map((item, i) => ({
        ...item,
        index: (newValue.data.page - 1) * newValue.data.pagesize + (i + 1)
      }))
      state.subjectManagementList = newValue.data
    }
}
const actions = {
    async updateSubjectList({ commit }, params) {
        const res = await subjectApi.simple(params)
        commit('SET_SUBJECT_LIST', res)
    },
    async updateSimpleList({ commit }, params) {
        const res = await directoryApi.simple(params)
        commit('SET_SIMPLE_LIST', res)
    },
    async updateTagList({ commit }, params) {
        const res = await simpleApi.simple(params)
        commit('SET_TAG_LIST', res)
    },
    async updatesubjectManagementList({ commit }, params) {
      const res = await subjectApi.list(params)
      commit('SET_SUBJECTMANAGEMENT_LIST', res)
    },
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}
